package main

import (
	"fmt"
	"log"
	"net"
	"time"
)

func main() {

	addr := &net.UDPAddr{
		IP:   net.ParseIP("127.0.0.1"),
		Port: 3000,
	}

	udp, err := net.ListenUDP("udp", addr)
	if err != nil {
		log.Fatal(err)
		return
	}

	remoteAddr := &net.UDPAddr{
		IP:   net.ParseIP("127.0.0.1"),
		Port: 2000,
	}
	_, err = udp.WriteToUDP([]byte("hello"), remoteAddr)
	if err != nil {
		fmt.Println("发送消息异常", err)
		return
	}
	time.Sleep(time.Second)

	data := make([]byte, 1024)
	n, err := udp.Read(data)
	if err != nil {
		fmt.Println("接受服务器消息异常", err)
		return
	}
	fmt.Println(string(data[:n]))
}
